//
//  ZJMusicTableViewCell.m
//  BreadTravel
//
//  Created by 张健 on 15/12/30.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ZJMusicTableViewCell.h"

@implementation ZJMusicTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setView];
    }
    return self;
}

- (void)setView{
    
    self.headImageView = [[UIImageView alloc]init];
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = 20;
    self.headImageView.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.headImageView];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.and.left.mas_equalTo(10);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
    }];
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.numberOfLines = 2;
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.headImageView.mas_right).offset(20);
        make.top.equalTo(self.headImageView).offset(7);
        make.right.mas_equalTo(-20);
    }];
    
    self.like = [[UILabel alloc]init];
    self.like.alpha = 0.5;
    self.like.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.like];
    [self.like mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.titleLabel.mas_bottom).offset(7);
        make.left.equalTo(self.titleLabel);
        make.width.mas_equalTo(90);
    }];
    
    self.playtimes = [[UILabel alloc]init];
    self.playtimes.alpha = 0.5;
    self.playtimes.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.playtimes];
    [self.playtimes mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.like);
        make.left.equalTo(self.like.mas_right).offset(10);
        make.width.mas_equalTo(120);
    }];
    
    self.subtitle = [[UILabel alloc]init];
    self.subtitle.font = [UIFont systemFontOfSize:12];
    self.subtitle.alpha = 0.8;
    self.subtitle.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.subtitle];
    [self.subtitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(-10);
        make.right.mas_equalTo(-10);
        make.width.mas_equalTo(150);
    }];
}

-(void)setModel:(ZJMusicModel *)model{
    
    NSURL *url = [NSURL URLWithString:model.coverSmall];
    [self.headImageView sd_setImageWithURL:url placeholderImage:IMAGE];
    
    self.titleLabel.text = model.title;
    self.like.text = [NSString stringWithFormat:@"喜欢: %ld人",model.likes];
    self.playtimes.text = [NSString stringWithFormat:@"播放: %.1f万人",model.playtimes/1000.0];
    self.subtitle.text = [NSString stringWithFormat:@"by %@",model.nickname];
}

@end
